<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<title>DOM操作-练习</title>
		<style type="text/css">
			body {
				font-size: 13px;
				line-height: 25px;
			}
			
			table {
				border-top: 1px solid #333;
				border-left: 1px solid #333;
				width: 300px;
			}
			
			td {
				border-right: 1px solid #333;
				border-bottom: 1px solid #333;
			}
			
			.center {
				text-align: center;
			}
		</style>
		<script src="js/jquery-3.5.1.min.js"></script>
		<script>
			// function addRow() {
			// 	var fRow = document.getElementById("row3");
			// 	var newRow = document.createElement("tr"); //创建行节点
			// 	var col1 = document.createElement("td"); //创建单元格节点
			// 	col1.innerHTML = "幸福从天而降"; //为单元格添加文本
			// 	var col2 = document.createElement("td");
			// 	col2.innerHTML = "&yen;18.50";
			// 	col2.setAttribute("align", "center");
			// 	newRow.appendChild(col1); //把单元格添加到行节点中
			// 	newRow.appendChild(col2);
			// 	document.getElementById("row1").parentNode.insertBefore(newRow, fRow); //把行节点添加到表格末尾
			// }
			
			//179000629徐阳光
			function addRow() {
				var tnew1 = $("<tr><td>幸福从天而降</td><td class='center'>&yen;18.50</td>tr><br>");
				$("#row3").before(tnew1);
			}
			
			//标题行设置为字体加粗、文本居中显示，背景颜色为灰色
			function updateRow(){
				$("#row1").css({"background-color":"#00FFFF","font-weight":"bold","text-align":"center"});
			}
			

			//删除
			function delRow(){
				var dRow = document.getElementsByTagName("tr");
				$("tr:eq(2)").remove();
			}
			
			//克隆
			function copyRow(){
				var r = $("#row3").clone();
				r.insertAfter("#row3");
			}
			
		</script>
	</head>

	<body>
		<table border="0" cellspacing="0" cellpadding="0" id="myTable">
			<tr id="row1">
				<td>书名</td>
				<td>价格</td>
			</tr>
			<tr id="row2">
				<td>看得见风景的房间</td>
				<td class="center">&yen;30.00</td>
			</tr>
			<tr id="row3">
				<td>60个瞬间</td>
				<td class="center">&yen;32.00</td>
			</tr>
		</table>
		<input name="b1" type="button" value="增加一行" onclick="addRow()" />
		<input name="b2" type="button" value="删除第2行" onclick="delRow()" />
		<input name="b3" type="button" value="修改标题样式" onclick="updateRow()" />
		<input name="b4" type="button" value="复制最后一行" onclick="copyRow()" />

	</body>

</html>